package cn.net.isir.core;

import cn.net.isir.tasker.AlipaySignHandleTask;
import cn.net.isir.tasker.ShopTurnTask;
import org.apache.log4j.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author liuxubo
 * @filename SystemLoadListener.java
 * @package cn.net.isir.core
 * @email lxb@isir.net.cn
 * @date 2018/11/19
 * @comment
 * @since 1.8
 */
public class SystemLoadListener implements ServletContextListener {

    /**
     * logger
     */
    private static Logger logger = Logger.getLogger(SystemLoadListener.class);

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //check the jedis
        JedisManager jedisManager = (JedisManager) SpringApplicationContextUtils.getBean("jedisManager");
        if (!jedisManager.checkResource()) {
            logger.error("=================================================\n");
            logger.error("jedis check fail!\n");
            logger.error("Please check the jedis service2.\n");
            logger.error("=================================================\n");
            System.exit(0);
        }
        logger.info("jedis check successful!");
        //执行扫描签约状态的定时任务
//        AlipaySignHandleTask.run();
        ShopTurnTask.run();
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
